<?php
/**
 * Created by PhpStorm.
 * User: CPR137
 * Date: 2018/1/24
 * Time: 13:54
 */

namespace app\modules\common;


class Message
{
    protected static $instance;
    protected $message;
    protected $info;

    private function __construct()
    {
    }

    /**
     * 获取类实例化对象
     * @return $this
     */
    public static function getInstance()
    {
        if (empty(self::$instance)) {
            self::$instance = new self;
        }
        return self::$instance;
    }

    /**
     * 设置消息
     * @param $msg
     */
    public static function setMessage($msg)
    {
        self::getInstance()->message = $msg;
    }

    /**
     * 获取消息
     * @return mixed
     */
    public static function getMessage()
    {
        return self::getInstance()->message;
    }

    /**
     * 设置数据
     * @param $name
     * @param null $value
     */
    public static function setInfo($key, $value = NULL)
    {
        self::getInstance()->info[$key] = $value;
    }

    /**
     * 获取数据
     * @param $name
     * @return null
     */
    public static function getInfo($key)
    {
        $return = null;
        if (isset(self::getInstance()->info[$key])) {
            $return = self::getInstance()->info[$key];
        }
        return $return;
    }

    /**
     * 删除数据
     * @access public
     * @author furong
     * @param $key
     * @return bool
     * @since  2018年1月25日 09:34:40
     * @abstract
     */
    public function delInfo($key)
    {
        $return = true;
        if (isset(self::getInstance()->info[$key])) {
            unset(self::getInstance()->info[$key]);
        }
        return $return;
    }


}